﻿
@using hc.epm.DataModel.Business;
@using System.Collections.Generic;
@model IEnumerable<Epm_AdPutRecord>
@{
    ViewBag.Title = "首页";
    Layout = "~/Views/Shared/_LayoutHc.cshtml";
}
<style type="text/css">
    .layui-form td {
        word-break: break-all;
    }
</style>
<div class="content-right date-wrap fl c">
    <div class="search mt5">
        <form class="layui-form" action="" method="get">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">广告名称 : </label>
                    <div class="layui-input-inline"><input type="text" name="AdName" id="AdName" placeholder="请输入广告名称" autocomplete="off" class="layui-input" value="@ViewBag.AdName" /></div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">广告位 : </label>
                    <div class="layui-input-inline">
                        <select class="form-control  show-tick" tabindex="-98" id="AdTargetName" name="AdTargetName">
                            @if (ViewBag.AdTargetList.Count > 0 && ViewBag.AdTargetList != null)
                            {
                                <option value="">--请选择--</option>
                                foreach (var item in ViewBag.AdTargetList)
                                {
                                    <option value="@item.Name">@item.Name</option>
                                }
                            }
                        </select>

                    </div>
                </div>

                <input type="submit" class="layui-btn layui-btn-radius layui-btn-warm" lay-filter="search" value="查询" />
            </div>
        </form>
    </div>
    <div class="main mt5">

        <div class="btns">
            <a href="javascript:;" data-right="add" id="add" class="checkright" style="display: inline;">新 增</a>
            <a href="javascript:;" data-right="delete" id="delete" class="checkright" style="display: inline;">删 除</a>
        </div>
        <div class="layui-form">
            <table class="layui-table" style="text-align:center">
                <thead>
                    <tr>
                        <th class="table-center">
                            <input type="checkbox" lay-skin="primary" lay-filter="allChoose" />
                            <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                        </th>
                        <th class="table-center">序号</th>
                        <th class="table-center">广告位编码</th>
                        <th class="table-center">广告位名称</th>
                        <th class="table-center">广告名称</th>
                        <th class="table-center">价格(元)</th>
                        <th class="table-center">广告类型</th>
                        <th class="table-center">开始时间</th>
                        <th class="table-center">结束时间</th>
                        <th class="table-center">排序</th>
                        <th class="table-center">是否启用</th>
                        <th class="table-center">操作</th>
                    </tr>
                </thead>
                <tbody>
                    @{
                        int index = 0;
                    }
                    @if (Model != null && Model.Count() > 0)
                    {
                        foreach (var item in Model)
                        {
                            index++;
                            <tr>
                                <td style="text-align:center">
                                    <input type="checkbox" lay-skin="primary" />
                                    <input type="hidden" name="id-@item.SId" id="id-@item.SId" value="@item.SId" />
                                </td>
                                <td class="table-center">@index</td>
                                <td>@item.AdTargetNum</td>
                                <td>@item.AdTargetName</td>
                                <td>@item.AdName</td>
                                <td>@item.Price</td>
                                <td>@item.AdTypeName</td>
                                <td>@item.StartTime</td>
                                <td>@item.EndTime</td>
                                <td>@item.Sort</td>

                                <td class="table-center">
                                    @if (item.State == 1)
                                    {
                                        <a href="javascript:;" class='change-state' data-itemid="@item.SId" data-value="0"  title="启用/禁用"><i class='glyphicon glyphicon-ok-sign handle-blue'></i></a>
                                    }
                                    else
                                    {
                                        <a href="javascript:;" class='change-state' data-itemid="@item.SId" data-value="1"  title="启用/禁用"><i class='glyphicon glyphicon-remove-sign handle-red'></i></a>
                                    }
                                </td>
                                <td class="table-center">
                                    <a href="javascript:;" class="editor-link " data-itemid="@item.SId" title="编辑" ><i class='glyphicon glyphicon-pencil handle-blue'></i></a>
                                </td>
                            </tr>
                        }
                    }
                    else
                    {
                        <tr>
                            <td colspan="12" class="table-center">
                                暂无数据
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
        </div>
        <div id="page"></div>
    </div>
</div>
<script>
    //若无数据隐藏分页组件
    if ('@ViewBag.Total' == 0) {
        $("#page").hide();
    }
    layui.use(['layer', 'form', 'element', 'laypage'], function () {
        var layer = layui.layer, form = layui.form, element = layui.element, $ = layui.jquery, laypage = layui.laypage;
        //分页
        laypage.render({
            elem: 'page',
            count: '@ViewBag.Total',
            curr: '@ViewBag.pageIndex',
            layout: ['prev', 'page', 'next', 'skip', 'count'],
            jump: function (obj, first) {
                if (!first) {
                    //得到了当前页，用于向服务端请求对应数据
                    var curr = obj.curr;
                    var search = $("form").serialize();
                    window.location.href = "/HcAdPutRecord/Index?pageIndex=" + curr + "&" + search;
                }
            }
        });
        //全选
        form.on('checkbox(allChoose)', function (data) {
            var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
            child.each(function (index, item) {
                item.checked = data.elem.checked;
            });
            form.render('checkbox');
        });
        //删除
        $("#delete").click(function () {
            var chkItems = $('.layui-table tbody input[type="checkbox"]:checked');
            var ids = "";
            chkItems.each(function (index, item) {
                var hfId = $(this).parent().find("input[type='hidden']");
                ids += hfId.val() + ",";
            });
            if (ids != "") {
                layer.confirm("确认要删除所选择的项？", { icon: 3 }, function () {
                    $.post("Delete", { ids: ids }, function (data) {
                        if (data.Flag) {
                            layer.msg("删除成功", { time: 1000, icon: 1 });
                            var search = $("form").serialize();
                            window.location.href = "/HcAdPutRecord/Index?pageIndex=1&" + search;
                        } else {
                            layer.alert(data.Message, { icon: 2 });
                        }
                    }, "json");
                }, function () {
                    return;
                })

            } else {
                layer.alert("请先选择要删除的数据", { icon: 2 });
            }
        });
    });

    //修改
    $(".editor-link").click(function () {
        var id = $(this).data("itemid");
        if (id != "") {
            layer.open({
                type: 2,
                title: GetLayerTitle("广告投放记录-编辑"),
                shadeClose: false, //点击遮罩关闭层
                area: [BigLayerWidth, '600px'],
                content: '/HcAdPutRecord/Edit/' + id
            });
        }

    });

    //增加
    $("#add").click(function () {
        layer.open({
            type: 2,
            title: GetLayerTitle("广告投放记录-添加"),
            shadeClose: false, //点击遮罩关闭层
            area: [BigLayerWidth, '600px'],
            content: '/HcAdPutRecord/Add'
        });
    });

    //确认状态切换
    $(".change-state").click(function () {
        var id = $(this).data("itemid");
        var state = $(this).data("value");
        var mes = "";
        if (state == 0) {
            mes="确认要禁用所选择的项？"
        } else if (state == 1) {
            mes = "确认要启用所选择的项？"
        }
        if (id != '') {
            layer.confirm(mes, { icon: 3 }, function () {
                $.post("ChangeState", { id: id, state: state }, function (data) {
                    if (data.Flag) {
                        window.location.href = "/HcAdPutRecord/Index";
                        layer.msg("操作成功！", { time: 1000, icon: 1 });
                    } else {
                        layer.alert(data.Message, { icon: 2 });

                    }
                })
            })
        } else {
            layer.alert("请选择要操作的项！")
        }
    })

</script>

